package com.dingli.admin.service.impl;

import com.dingli.admin.service.IBankService;
import com.dingli.framework.entity.Bank;
import com.dingli.framework.mapper.BankMapper;
import com.dingli.framework.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BankService implements IBankService {

    @Autowired
    private BankMapper bankMapper;

    @Override
    public Response<List<Bank>> list(String search) {
        return new Response<>(200, "success", bankMapper.list(search));
    }

    @Override
    public Response<Long> insert(Bank bank) {
        int count = bankMapper.insert(bank);
        if (count > 0) {
            return new Response(200, "success",bank.getBankId());
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Object> updateById(Bank bank) {
        int count = bankMapper.updateById(bank);
        if (count > 0) {
            return new Response<>(200, "success",bank.getBankId());
        } else {
            return new Response<>(500, "failed");
        }

    }

    @Override
    public Response<Object> deleteById(Long bankId) {
        int count = bankMapper.deleteById(bankId);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }

    }

    @Override
    public Response<Object> deleteBatch(List<Long> idList) {
        int count = bankMapper.deleteBatch(idList);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }

    }
}
